package svgedit.gui;

/**
 * Manages user preferences for the GUI.
 * 
 * Internally uses {@link java.util.prefs.Preferences} to store preferences.
 * 
 */
public class Preferences
{

	private java.util.prefs.Preferences preferences;

	/** Root path for all preferences */
	public static final String ROOT_NODE = "svgedit.gui";

	/** Key for the default path to use for file dialogs */
	public static final String KEY_DEFAULT_PATH = "defaultPath";

	/** Store the Filename for saving */
	public static final String CURRENT_FILE = "defaultName";

	/**
	 * Creates a new preferences object. Only one object is required, as all
	 * preferences are stored per-user.
	 */
	public Preferences()
	{
		preferences = java.util.prefs.Preferences.userRoot().node(ROOT_NODE);
	}

	/**
	 * Gets the current filename to use in save.
	 * 
	 * @return a string filename of the current file used.
	 */
	public String getCurrentCurrentFile()
	{
		return preferences.get(CURRENT_FILE, null);
	}

	/**
	 * Sets the current filename to use in save.
	 * 
	 */
	public void setCurrentFile(String n)
	{
		preferences.put(CURRENT_FILE, n);
	}

	/**
	 * Gets the default path to present to the user when showing a file dialog
	 * 
	 * @return a string giving the default path, or {@literal null} if the
	 *         preference hasn't been set
	 */
	public String getDefaultPath()
	{
		return preferences.get(KEY_DEFAULT_PATH, null);
	}

	/**
	 * Sets the default path to present to the user when showing a file dialog
	 * 
	 * @param path
	 *            the default path to set
	 */
	public void setDefaultPath(String path)
	{
		preferences.put(KEY_DEFAULT_PATH, path);
	}

}
